import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import collections as matcoll
import seaborn
seaborn.set(font_scale = 2)
import scipy.stats as stats
from sklearn import preprocessing
price = pd.read_csv("Stock Prices.csv",index_col='Date', parse_dates=True, dayfirst=True)
price.head()
price.plot(figsize=(20,10), linewidth = 2, color = ['royalblue', 'darkorchid', 'salmon', 'red'])
plt.title("Line Chart for Stock Prices", fontsize=30)
plt.xlabel("Date", fontsize = 25)
plt.ylabel("Price", fontsize = 25)
plt.legend(prop={'size': 25})
df = pd.read_csv("Data.csv",index_col='Date', parse_dates=True, dayfirst=True)
df.head()
df['ATVI'].plot(figsize=(20,10), linewidth = 2, color = ['royalblue'])
plt.title("Line Chart for ATVI Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
df['TTWO'].plot(figsize=(20,10), linewidth = 2, color = ['darkorchid'])
plt.title("Line Chart for TTWO Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
df['GME'].plot(figsize=(20,10), linewidth = 2, color = ['salmon'])
plt.title("Line Chart for GME Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
df['ZNGA'].plot(figsize=(20,10), linewidth = 2, color = ['red'])
plt.title("Line Chart for ZNGA Returns", fontsize=30)
plt.ylabel("Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
auto_corr = pd.DataFrame()
auto_corr['S_No'] = list(range(1,101))
auto_corr["ATVI"] = [df["ATVI"].autocorr(lag = i) for i in range(1,101)]
auto_corr["TTWO"] = [df["TTWO"].autocorr(lag = i) for i in range(1,101)]
auto_corr["GME"] = [df["GME"].autocorr(lag = i) for i in range(1,101)]
auto_corr["ZNGA"] = [df["ZNGA"].autocorr(lag = i) for i in range(1,101)]
auto_corr.head()
plt.figure(figsize=(20,10))
auto_corr["ATVI"].plot(color = 'royalblue')
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ATVI: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr["TTWO"].plot(color = 'darkorchid')
plt.axhline(y=0, color='k', linestyle='--')
plt.title("TTWO: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr["GME"].plot(color = "salmon")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("GME: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr["ZNGA"].plot(color = "red")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ZNGA: Autocorrelation vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
from statsmodels.regression.linear_model import OLS
from statsmodels.stats.stattools import durbin_watson
def dw(data):
ols_res = OLS(data, np.ones(len(data))).fit()
return durbin_watson(ols_res.resid)
#which should not be correlated, thus giving a value close to 2
print("DW of ATVI = %f" % dw(df["ATVI"]))
print("DW of TTWO = %f" % dw(df["TTWO"]))
print("DW of GME = %f" % dw(df["GME"]))
print("DW of ZNGA = %f" % dw(df["ZNGA"]))
df_sq = pd.DataFrame()
for column in df.columns:
df_sq[column] = df[column]**2
#which should not be correlated, thus giving a value close to 2
print("DW of ATVI = %f" % dw(df_sq["ATVI"]))
print("DW of TTWO = %f" % dw(df_sq["TTWO"]))
print("DW of GME = %f" % dw(df_sq["GME"]))
print("DW of ZNGA = %f" % dw(df_sq["ZNGA"]))
len(df_sq["ATVI"])
auto_corr_sq = pd.DataFrame()
auto_corr_sq['S_No'] = list(range(1,101))
auto_corr_sq["ATVI"] = [df_sq["ATVI"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["TTWO"] = [df_sq["TTWO"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["GME"] = [df_sq["GME"].autocorr(lag = i) for i in range(1,101)]
auto_corr_sq["ZNGA"] = [df_sq["ZNGA"].autocorr(lag = i) for i in range(1,101)]
plt.figure(figsize=(20,10))
auto_corr_sq["ATVI"].plot(color = "royalblue")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ATVI: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr_sq["TTWO"].plot(color = "darkorchid")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("TTWO: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr_sq["GME"].plot(color = "salmon")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("GME: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
plt.figure(figsize=(20,10))
auto_corr_sq["ZNGA"].plot(color = "red")
plt.axhline(y=0, color='k', linestyle='--')
plt.title("ZNGA: Autocorrelation - Squared Returns vs lag", fontsize = 30)
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Autocorrelation", fontsize = 25)
df_sq['ATVI'].plot(figsize=(20,10), linewidth = 2, color = ['royalblue'])
plt.title("Line Chart for ATVI Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
#ATVI
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['ATVI'].shift(1)[1:],df_sq['ATVI'][1:])
abline_values = [slope * i + intercept for i in df_sq['ATVI'].shift(1)]
plt.figure(figsize=(20,10))
plt.scatter(df_sq['ATVI'].shift(1),df_sq['ATVI'], color = "royalblue")
plt.title("ATVI Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['ATVI'].shift(1), abline_values, 'k--', linewidth = 0.75)
#ATVI
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
df_sq['TTWO'].plot(figsize=(20,10), linewidth = 2, color = ['darkorchid'])
plt.title("Line Chart for TTWO Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['TTWO'].shift(1)[1:],df_sq['TTWO'][1:])
abline_values = [slope * i + intercept for i in df_sq['TTWO'].shift(1)]
plt.figure(figsize=(20,10))
plt.scatter(df_sq['TTWO'].shift(1),df_sq['TTWO'], color = "darkorchid")
plt.title("TTWO Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['TTWO'].shift(1), abline_values, 'k--', linewidth = 0.75)
#TTWO
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
df_sq['GME'].plot(figsize=(20,10), linewidth = 2, color = ['salmon'])
plt.title("Line Chart for GME Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['GME'].shift(1)[1:],df_sq['GME'][1:])
abline_values = [slope * i + intercept for i in df_sq['GME'].shift(1)]
plt.figure(figsize=(20,10))
plt.scatter(df_sq['GME'].shift(1),df_sq['GME'], color = "salmon")
plt.title("GME Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['GME'].shift(1), abline_values, 'k--', linewidth = 0.75)
#GME
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
df_sq['ZNGA'].plot(figsize=(20,10), linewidth = 2, color = ['red'])
plt.title("Line Chart for ZNGA Squared Returns", fontsize=30)
plt.ylabel("Squared Return", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
#TTWO
slope, intercept, r_value, p_value, std_err = stats.linregress(df_sq['ZNGA'].shift(1)[1:],df_sq['ZNGA'][1:])
abline_values = [slope * i + intercept for i in df_sq['ZNGA'].shift(1)]
plt.figure(figsize=(20,10))
plt.scatter(df_sq['ZNGA'].shift(1),df_sq['ZNGA'], color = "red")
plt.title("ZNGA Day t Squared Return vs Day t-1 Squared Return", fontsize = 30)
plt.ylabel("Day t Squared Return", fontsize = 25)
plt.xlabel("Day t-1 Squared Return", fontsize = 25)
plt.plot(df_sq['ZNGA'].shift(1), abline_values, 'k--', linewidth = 0.75)
#ZNGA
print("slope = ", slope)
print("intercept = ", intercept)
print("r_squared = ", r_value**2)
print("p_value = ", p_value)
import statsmodels.api as sm
sm.stats.acorr_ljungbox(df["ATVI"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df["TTWO"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df["GME"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df["ZNGA"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df_sq["ATVI"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df_sq["TTWO"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df_sq["GME"], 20, boxpierce = True, return_df = True)
sm.stats.acorr_ljungbox(df_sq["ZNGA"], 20, boxpierce = True, return_df = True)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["ATVI"], lags=100, color = "royalblue", ax = ax, title='ACF Plot: ATVI Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["TTWO"], lags=100, color = "darkorchid", ax = ax, title='ACF Plot: TTWO Returns',zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["GME"], lags=100, color = "salmon", ax = ax, title='ACF Plot: GME Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df["ZNGA"], lags=100, color = "red", ax = ax, title='ACF Plot: ZNGA Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["ATVI"], lags=100, color = "royalblue", ax = ax, title='ACF Plot: ATVI Squared Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["TTWO"], lags=100, color = "darkorchid", ax = ax, title='ACF Plot: TTWO Squared Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["GME"], lags=100, color = "salmon", ax = ax, title='ACF Plot: GME Squared Returns', zero=False)
plt.figsize=(20,10)
fig, ax = plt.subplots(figsize=(20, 10))
sm.graphics.tsa.plot_acf(df_sq["ZNGA"], lags=100, color = "red", ax = ax, title='ACF Plot: ZNGA Squared Returns', zero=False)
plt.figsize=(20,10)
ATVIh = pd.read_csv("Horizon Analysis/ATVI Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
ATVIh.head()
ATVIh.mean()
ATVIh.std()
ATVIh.mean()/ATVIh.std()
ATVIh.skew()
ATVIh.kurt()
TTWOh = pd.read_csv("Horizon Analysis/TTWO Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
TTWOh.head()
TTWOh.mean()
TTWOh.std()
TTWOh.mean()/ATVIh.std()
TTWOh.skew()
TTWOh.kurt()
GMEh = pd.read_csv("Horizon Analysis/GME Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
GMEh.head()
GMEh.mean()
GMEh.std()
GMEh.mean()/ATVIh.std()
GMEh.skew()
GMEh.kurt()
ZNGAh = pd.read_csv("Horizon Analysis/ZNGA Horizon.csv",index_col='Date', parse_dates=True, dayfirst=True)
ZNGAh.head()
ZNGAh.mean()
ZNGAh.std()
ZNGAh.mean()/ATVIh.std()
ZNGAh.skew()
ZNGAh.kurt()
def emwa(R, l):
emwa_vol = pd.DataFrame(index = R.index, columns = R.columns)
emwa_vol.iloc[0,:] = R.std()
for i in range(1, len(R)):
emwa_vol.iloc[i,:] = (l*(emwa_vol.iloc[i-1,:]).pow(2) + (1-l)*(R.iloc[i-1,:]).pow(2)).pow(1/2)
return emwa_vol
#lambda of 0.94 is generally used
df_emwa = emwa(df, 0.94)
plt.figure(figsize=(30,20))
plt.plot(df_sq["ATVI"], color = "royalblue")
plt.plot(df_emwa["ATVI"].pow(2), color = "k", linewidth = 3)
plt.legend(["ATVI Squared Returns","ATVI EMWA Variance"], prop={'size': 30})
plt.title("ATVI: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
plt.figure(figsize=(30,25))
plt.plot(df_sq["TTWO"], color = "darkorchid")
plt.plot(df_emwa["TTWO"].pow(2), color = "k", linewidth = 3)
plt.legend(["TTWO Squared Returns","TTWO EMWA Variance"], prop={'size': 30})
plt.title("TTWO: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
plt.figure(figsize=(30,20))
plt.plot(df_sq["GME"], color = "salmon")
plt.plot(df_emwa["GME"].pow(2), color = "k", linewidth = 3)
plt.legend(["GME Squared Returns","GME EMWA Variance"], prop={'size': 30})
plt.title("GME: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
plt.figure(figsize=(30,20))
plt.plot(df_sq["ZNGA"], color = "red")
plt.plot(df_emwa["ZNGA"].pow(2), color = "k", linewidth = 3)
plt.legend(["ZNGA Squared Returns","ZNGA EMWA Variance"], prop={'size': 30})
plt.title("ZNGA: Squared Returns and EMWA Variance", fontsize = 30)
plt.ylabel("Squared Returns/Variance", fontsize = 25)
plt.xlabel("Date", fontsize = 25)
from scipy.stats.stats import pearsonr
n = 100
lcorr = pd.DataFrame(index = list(range(1,n+1)), columns = df.columns)
for i in range(1, n+1):
for j in range(len(lcorr.columns)):
lcorr.iloc[i-1,j] = pearsonr(df_sq.iloc[i:,j].values, df.iloc[0:(len(df)-i),j].values)[0]
lcorr
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ATVI'], linefmt = "k")
plt.setp(baseline, color='royalblue', linewidth=2)
plt.setp(markerline, color = 'royalblue', markersize = 15)
plt.title("TTWO: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['TTWO'], linefmt = "k")
plt.setp(baseline, color='darkorchid', linewidth=2)
plt.setp(markerline, color = 'darkorchid', markersize = 15)
plt.title("TTWO: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['GME'], linefmt = "k")
plt.setp(baseline, color='salmon', linewidth=2)
plt.setp(markerline, color = 'salmon', markersize = 15)
plt.title("GME: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), lcorr['ZNGA'], linefmt = "k")
plt.setp(baseline, color='red', linewidth=2)
plt.setp(markerline, color = 'red', markersize = 15)
plt.title("ZNGA: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
ind = pd.read_csv("Indices.csv",index_col='Date', parse_dates=True, dayfirst=True)
ind.head()
indcorr = pd.DataFrame(index = list(range(1,n+1)), columns = ind.columns)
for i in range(1, n+1):
for j in range(len(indcorr.columns)):
indcorr.iloc[i-1,j] = pearsonr(ind.iloc[i:,j].pow(2), ind.iloc[0:(len(ind)-i),j].values)[0]
indcorr.head()
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['S&P500'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("S&P 500: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['NASDAQ'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("NASDAQ: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['DJIA'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("DJIA: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.figure(figsize=(30,20))
markerline, stemlines, baseline = plt.stem(np.arange(1,101), indcorr['Russell2000'], linefmt = "k")
plt.setp(baseline, color='darkgreen', linewidth=2)
plt.setp(markerline, color = 'darkgreen', markersize = 15)
plt.title("Russell2000: correlation - Squared Returns vs lagged Returns", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
#Calculate kurtosis
kurto = pd.DataFrame([stats.kurtosis(df[columns].values) for columns in df.columns], index = df.columns, columns = ['Kurtosis'])
kurto
df.kurt()
from scipy.stats import norm
import matplotlib.pyplot as plt
(mu, sigma) = norm.fit(preprocessing.scale(df["ATVI"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["ATVI"]), 60, density = True, color = 'royalblue')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of ATVI", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(df["TTWO"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["TTWO"]), 60, density = True, color = 'darkorchid')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of TTWO", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(df["GME"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["GME"]), 60, density = True, color = 'salmon')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of GME", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(df["ZNGA"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(df["ZNGA"]), 60, density = True, color = 'red')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of ZNGA", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
rskew = pd.DataFrame([stats.skew(df[columns].values) for columns in df.columns], index = df.columns, columns = ['Skewness'])
rskew
fxdf = pd.read_csv("FX Data.csv")
fxdf['Date'] = pd.to_datetime(fxdf['Date'])
fxdf = fxdf.set_index(['Date'])
fxdf.head()
fxskew = pd.DataFrame([stats.skew(fxdf[columns].values) for columns in fxdf.columns], index = fxdf.columns, columns = ['Skewness'])
fxskew
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDGBP"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDGBP"]), 60, density = True, color = 'cadetblue')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of USDGBP", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDEUR"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDEUR"]), 60, density = True, color = 'cadetblue')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of USDEUR", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDJPY"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDJPY"]), 60, density = True, color = 'cadetblue')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of USDJPY", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
(mu, sigma) = norm.fit(preprocessing.scale(fxdf["USDCHF"]))
plt.figure(figsize=(30,20))
n, bins, patches = plt.hist(preprocessing.scale(fxdf["USDCHF"]), 60, density = True, color = 'cadetblue')
y = norm.pdf( bins, mu, sigma)
l = plt.plot(bins, y, 'k--', linewidth=2)
plt.axvline(0, color='k', linestyle='--', linewidth = 3)
plt.title("Histogram of Returns of USDCHF", fontsize=30)
plt.legend(["PDF from a Standard Normal Distribution","Histogram from data"], prop={'size': 30})
rjbs = pd.DataFrame([stats.jarque_bera(preprocessing.scale(df[columns].values)).statistic for columns in df.columns], index = df.columns, columns = ['JB Statistic'])
rjbs["p-value"] = [stats.jarque_bera(preprocessing.scale(df[columns].values)).pvalue for columns in df.columns]
rjbs
fxkurto = pd.DataFrame([stats.kurtosis(fxdf[columns].values) for columns in fxdf.columns], index = fxdf.columns, columns = ['Kurtosis'])
fxkurto
#JB Statistic for FX Return data
fxjbs = pd.DataFrame([stats.jarque_bera(preprocessing.scale(fxdf[columns].values)).statistic for columns in fxdf.columns], index = fxdf.columns, columns = ['JB Statistic'])
fxjbs["p-value"] = [stats.jarque_bera(preprocessing.scale(fxdf[columns].values)).pvalue for columns in fxdf.columns]
fxjbs
df.corr()
from scipy.stats.stats import pearsonr
def lag_cross_corr(x,y,n = 100):
lcross_cov = pd.DataFrame(index = list(range(1,n+1)), columns = [x.name + "-" + y.name])
for i in range(1, n+1):
lcross_cov.iloc[i-1,0] = pearsonr(x[i:], y[0:(len(y)-i)])[0]
return lcross_cov
cross_corr_lag = pd.DataFrame(index = list(range(1,101)), columns = ["ATVI-TTWO","ATVI-GME","ATVI-ZNGA","TTWO-ATVI","TTWO-GME","TTWO-ZNGA","GME-ATVI","GME-TTWO","GME-ZNGA","ZNGA-ATVI","ZNGA-TTWO","ZNGA-GME"])
for name in cross_corr_lag.columns:
s1, s2 = name.split("-")
cross_corr_lag[name] = lag_cross_corr(df[s1],df[s2])
cross_corr_lag
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['ATVI-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ATVI-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ATVI-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ATVI Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ATVI-TTWO', 'ATVI-GME','ATVI-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['TTWO-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['TTWO-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['TTWO-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("TTWO Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['TTWO-ATVI', 'TTWO-GME','TTWO-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['GME-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['GME-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['GME-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("GME Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['GME-ATVI', 'GME-TTWO','GME-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_lag['ZNGA-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ZNGA-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_lag['ZNGA-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ZNGA Returns vs Other Stocks Lagged Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ZNGA-ATVI', 'ZNGA-TTWO','ZNGA-GME'], prop={'size': 30})
df_abs = df.abs()
df.head()
df_abs.head()
cross_corr_abs_lag = pd.DataFrame(index = list(range(1,101)), columns = ["ATVI-TTWO","ATVI-GME","ATVI-ZNGA","TTWO-ATVI","TTWO-GME","TTWO-ZNGA","GME-ATVI","GME-TTWO","GME-ZNGA","ZNGA-ATVI","ZNGA-TTWO","ZNGA-GME"])
for name in cross_corr_lag.columns:
s1, s2 = name.split("-")
cross_corr_abs_lag[name] = lag_cross_corr(df_abs[s1],df_abs[s2])
cross_corr_abs_lag
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['ATVI-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ATVI-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ATVI-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ATVI Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ATVI-TTWO', 'ATVI-GME','ATVI-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['TTWO-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['TTWO-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['TTWO-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("TTWO Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['TTWO-ATVI', 'TTWO-GME','TTWO-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['GME-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['GME-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['GME-ZNGA'], color = "red", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'red', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("GME Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['GME-ATVI', 'GME-TTWO','GME-ZNGA'], prop={'size': 30})
plt.figure(figsize=(30,20))
plt.plot(cross_corr_abs_lag['ZNGA-ATVI'], color = "royalblue", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'royalblue', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ZNGA-TTWO'], color = "darkorchid", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'darkorchid', markersize = 12, linewidth = 2)
plt.plot(cross_corr_abs_lag['ZNGA-GME'], color = "salmon", linestyle = 'dotted', markevery = 5, marker = 'o', markerfacecolor = 'salmon', markersize = 12, linewidth = 2)
plt.axhline(y=0, color='k', linestyle='--', linewidth = 2.5)
plt.title("ZNGA Absolute Returns vs Other Stocks Lagged Absolute Returns: Correlation", fontsize = 30)
plt.xticks(np.arange(0,101, 10))
plt.xlabel("Lag", fontsize = 25)
plt.ylabel("Correlation", fontsize = 25)
plt.legend(['ZNGA-ATVI', 'ZNGA-TTWO','ZNGA-GME'], prop={'size': 30})
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('ATVI: Multivariate Correlations', y = 1)
colors = ['darkorchid','salmon','red']
col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"
ATVI_cross_corr_lag = pd.concat([cross_corr_lag['ATVI-TTWO'], cross_corr_lag['ATVI-GME'], cross_corr_lag['ATVI-ZNGA']], axis = 1)
ATVI_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['ATVI-TTWO'], cross_corr_abs_lag['ATVI-GME'], cross_corr_abs_lag['ATVI-ZNGA']], axis = 1)
for j,i in enumerate([0,1,2]):
markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ATVI_cross_corr_lag.iloc[:,i].values, linefmt = "k")
ax[i,0].set_title(ATVI_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
ax[i,0].set_xlabel("Lag", fontsize = 15)
ax[i,0].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ATVI_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
ax[i,1].set_title(ATVI_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
ax[i,1].set_xlabel("Lag", fontsize = 15)
ax[i,1].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
fig.tight_layout()
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('TTWO: Multivariate Correlations'+'\n', y = 1)
colors = ['royalblue','salmon','red']
col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"
TTWO_cross_corr_lag = pd.concat([cross_corr_lag['TTWO-ATVI'], cross_corr_lag['TTWO-GME'], cross_corr_lag['TTWO-ZNGA']], axis = 1)
TTWO_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['TTWO-ATVI'], cross_corr_abs_lag['TTWO-GME'], cross_corr_abs_lag['TTWO-ZNGA']], axis = 1)
for j,i in enumerate([0,1,2]):
markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), TTWO_cross_corr_lag.iloc[:,i].values, linefmt = "k")
ax[i,0].set_title(TTWO_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
ax[i,0].set_xlabel("Lag", fontsize = 15)
ax[i,0].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), TTWO_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
ax[i,1].set_title(TTWO_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
ax[i,1].set_xlabel("Lag", fontsize = 15)
ax[i,1].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
fig.tight_layout()
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('GME: Multivariate Correlations'+'\n', y = 1)
colors = ['royalblue','darkorchid','red']
col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"
GME_cross_corr_lag = pd.concat([cross_corr_lag['GME-ATVI'], cross_corr_lag['GME-TTWO'], cross_corr_lag['GME-ZNGA']], axis = 1)
GME_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['GME-ATVI'], cross_corr_abs_lag['GME-TTWO'], cross_corr_abs_lag['GME-ZNGA']], axis = 1)
for j,i in enumerate([0,1,2]):
markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), GME_cross_corr_lag.iloc[:,i].values, linefmt = "k")
ax[i,0].set_title(GME_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
ax[i,0].set_xlabel("Lag", fontsize = 15)
ax[i,0].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), GME_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
ax[i,1].set_title(GME_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
ax[i,1].set_xlabel("Lag", fontsize = 15)
ax[i,1].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
fig.tight_layout()
fig, ax = plt.subplots(3, 2, figsize=(15,15))
fig.suptitle('ZNGA: Multivariate Correlations'+'\n', y = 1)
colors = ['royalblue','darkorchid','salmon']
col1_title = " Lagged Returns Correlations"
col2_title = " Lagged Absolute Returns Correlations"
ZNGA_cross_corr_lag = pd.concat([cross_corr_lag['ZNGA-ATVI'], cross_corr_lag['ZNGA-TTWO'], cross_corr_lag['ZNGA-GME']], axis = 1)
ZNGA_cross_corr_abs_lag = pd.concat([cross_corr_abs_lag['ZNGA-ATVI'], cross_corr_abs_lag['ZNGA-TTWO'], cross_corr_abs_lag['ZNGA-GME']], axis = 1)
for j,i in enumerate([0,1,2]):
markerline, stemlines, baseline = ax[i,0].stem(list(range(1,101)), ZNGA_cross_corr_lag.iloc[:,i].values, linefmt = "k")
ax[i,0].set_title(ZNGA_cross_corr_lag.columns[j] + col1_title, fontsize = 20)
ax[i,0].set_xlabel("Lag", fontsize = 15)
ax[i,0].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
markerline, stemlines, baseline = ax[i,1].stem(list(range(1,101)), ZNGA_cross_corr_abs_lag.iloc[:,i].values, linefmt = "k")
ax[i,1].set_title(ZNGA_cross_corr_abs_lag.columns[j] + col2_title, fontsize = 20)
ax[i,1].set_xlabel("Lag", fontsize = 15)
ax[i,1].set_ylabel("Correlation", fontsize = 15)
plt.setp(baseline, color= colors[j], linewidth=2)
plt.setp(markerline, color = colors[j], markersize = 7.5)
fig.tight_layout()
df_norm = (df - df.mean())/df.std()
df_ext = df_norm[(df_norm.abs() > 2).any(1)]
er2 = pd.read_csv("Excess returns 2.csv",index_col='Date', parse_dates=True, dayfirst=True)
plt.figure(figsize=(30,20))
plt.scatter(x = er2.index, y = er2['ATVI'], color = 'royalblue', s = 300)
plt.scatter(x = er2.index, y = er2['TTWO'], color = 'darkorchid', s = 300)
plt.scatter(x = er2.index, y = er2['GME'], color = 'salmon', s = 300)
plt.scatter(x = er2.index, y = er2['ZNGA'], color = 'red', s = 300)
plt.axhline(y=0, color='k', linestyle='--')
plt.axvline(pd.to_datetime('2020-03-13'), color='darkred', linestyle='--', linewidth = 3)
plt.axvline(pd.to_datetime('2018-03-27'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2018-11-09'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-04'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-12'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-16'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-20'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-03-26'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2020-08-11'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.axvline(pd.to_datetime('2021-01-27'), color='darkgoldenrod', linestyle='--', linewidth = 1.5)
plt.title("Extreme Normalized Returns of Stocks")
plt.ylabel("Standard Deviations")
plt.xlabel("Date")
plt.legend(["_0","Movement in 4 Stocks ","Movement in 3 Stocks"])
n = [0,126,252,378,504,630,757]
for i in range(6):
print(df.iloc[n[i]:n[i+1],:].corr())
print("\n")